﻿#ifndef MYOPENGLWIDGET_H
#define MYOPENGLWIDGET_H

#include <QKeyEvent>
#include <QOpenGLFunctions_3_3_Core>
#include <QOpenGLShaderProgram>
#include <QOpenGLTexture>
#include <QOpenGLWidget>

#include <QTime>
#include <QTimer>
#include <QVector3D>
#include <QVector>
#include <math.h>
/*
    摄像机移动：
    const float radius = 10.0f;
    float       time   = m_time.elapsed() / 1000.0;
    float       camX   = sin( time ) * radius;
    float       camZ   = cos( time ) * radius;
    view.lookAt( QVector3D( camX, 0.0f, camZ ), cameraTarget, up );
*/

class MyOpenGLWidget : public QOpenGLWidget, QOpenGLFunctions_3_3_Core {
    Q_OBJECT
  public:
    enum Shape { None, Rect, Circle, Triangle };

    MyOpenGLWidget( QWidget *parent = nullptr );
    ~MyOpenGLWidget();

    void drawShape( Shape shape );
    void setWireframe( bool wireframe );

  protected:
    virtual void initializeGL();
    virtual void resizeGL( int w, int h );
    virtual void paintGL();
    virtual void keyPressEvent( QKeyEvent *event ) override;

  signals:

  public slots:
    void on_timerout();

  private:
    Shape                m_shape;
    QOpenGLShaderProgram m_shaderProgram;
    QOpenGLTexture *     m_textureWall;  // 1 步骤一
    QOpenGLTexture *     m_textureFreep; // 1 步骤一
    QOpenGLTexture *     m_textureSamll; // 1 步骤一

    QTimer m_timer;
    QTime  m_time;

    QVector3D cameraPos;
    QVector3D cameraTarget;
    QVector3D cameraDirection;
    QVector3D up;
    QVector3D cameraRight;
    QVector3D cameraUp;
};

#endif // MYOPENGLWIDGET_H
